package com.zfj.ArrayList;

import com.zfj.Collection.Student;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.ListIterator;

/**
 * @author zfj
 * @date 2022/3/5 -15:58
 * ArrayList使用
 * 存储结构：数组，数组结构实现，查询块，增删慢
 */
public class Demo1 {
	public static void main(String[] args) {
		//创建集合
		ArrayList arrayList=new ArrayList();
		//添加元素
		Student s1=new Student("张三",20);
		Student s2=new Student("李四",20);
		Student s3=new Student("王五",20);
		Student s4=new Student("赵六",20);
		arrayList.add(s1);
		arrayList.add(s2);
		arrayList.add(s3);
		arrayList.add(s4);
		System.out.println(arrayList.size());
		System.out.println(arrayList.toString());
		//删除
		arrayList.remove(new Student("张三",20));
		System.out.println(arrayList.toString());
		//遍历
		//迭代器
		Iterator iterator = arrayList.iterator();
		while (iterator.hasNext()){
			Student st=(Student) iterator.next();
			System.out.println(st);
		}
		//列表迭代器
		ListIterator list = arrayList.listIterator();
		System.out.println("=========列表迭代器===========");
		while (list.hasNext()){
			Student st=(Student) list.next();
			System.out.println(st);
		}
		//逆序列表迭代器
		System.out.println("=========逆序列表迭代器===========");
		while (list.hasPrevious()){
			Student st=(Student) list.previous();
			System.out.println(st);
		}
		//判断
		System.out.println(arrayList.isEmpty());
		System.out.println(arrayList.contains(new Student("赵六",20)));
		//查找
		System.out.println(arrayList.get(2));
	}
}
